package mysqlproxy;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Handler;

/**
 * @Author: admin
 * @Description:
 * @Date: 2018/11/26 17:22
 */

public class MysqlProxy {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket();
        serverSocket.bind(new InetSocketAddress(3316));

        while (true) {
            Socket socket = serverSocket.accept();
            new HandlerConn(socket).start();
        }
    }

    protected static class HandlerConn extends Thread {
        private Socket socket = null;
        InputStream in = null;

        @Override
        public void run() {
            try {
                in = socket.getInputStream();

                byte[] data = new byte[1000];
                int len=0;
                while ((len = in.read(data))> 0) {
                    System.out.println(len);
                    System.out.println(new String(data, 0, len, "utf8"));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public HandlerConn(Socket socket) {
            this.socket = socket;
        }
    }
}
